home *** CD-ROM | disk | FTP | other *** search
- Path: news.compuserve.com!newsmaster
- From: Philippe Verdy <100105.3120@compuserve.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Is it OK to delete const *type pointers?
- Date: 1 Apr 1996 23:48:16 GMT
- Organization: CompuServe Incorporated
- Message-ID: <4jpq00$lhj@dub-news-svc-6.compuserve.com>
- NNTP-Posting-Host: ad15-078.compuserve.com
-
- jlilley@ix.netcom.com (John Lilley) s'Θcrit :
- > In article <4jhjub$fpc@mag1.magmacom.com>, ezust@mag1.magmacom.com says...
- > >Some compilers let me do this, others do not. What I would like to know is,
- > >what does Stroustrup think? I.e. is it written somewhere in the ARM (I checked
- > >but can't find it) or in the draft standard? If somoene could e-mail me a
- > >quote or a pointer to a place where I can read where it says such a thing
- > >should or should not be allowed, I would appreciate it!
- > >
- > >const int* array= new int[30];
- > >delete[] array;
- >
- > The ARM says that it is valid to call the destructor for a const object.
- > This implies to me that it should also be legal to delete it. However,
- > I cannot find that explicitly stated.
- >
- > john lilley
- >
- Yes it is OK: the object it self is not modifiable, for the
- whole time it lives only. They can be destructed when needed.
- Beeing const means you can modify the object somebody has created
- for you.
- However be careful when you delete that object: it may be
- still referenced by other aliased pointers (when passing the
- const object pointer to a function), so these references
- could become invalid. But the same warning exists on all
- pointers, and on all local objects allocated on the stack,
- would they be const or not...
-